<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>姓名案例-计算属性</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!--准备一个容器-->
<div id="root">
    姓：<input type="text" v-model="firstName"><br>
    名：<input type="text" v-model="lastName"><br>
    ceshi：<input type="text" v-model="x"><br>
    姓名：<span>{{fullName}}</span><br>
<!--    姓名：<span>{{fullName}}</span><br>-->
<!--    姓名：<span>{{fullName}}</span><br>-->
</div>
</body>
<script type="text/javascript">
    Vue.config.productionTip=false
    const vm =new Vue({
        el:"#root",
        data:{
            firstName:"张",
            lastName:"三",
            x:'你好'
        },
        methods:{
          demo(){

          }
        },
       computed:{
            fullName:{
                //get:但有人读取fullname时，get就会被调用，且返回值就作为fullname的值
                get(){
                    console.log('get被调用')
                    //console.log(this)//此处this是vm
                    return this.firstName+"-"+this.lastName
                },
                //set会在fullname被修改时调用
                set(value){
                    console.log('set',value)
                    const arr =value.split('-')
                    this.firstName=arr[0]
                    this.lastName =arr[1]
                }
            }
       }
    })
</script>
</html>